<?php
/**
 * 平台每日数据
 */
namespace App\Models\MainDB\Statistics;

use Illuminate\Database\Eloquent\Model;

class PlatformEverydayData extends Model
{
    protected $table = 'ln_platform_everyday_data';

    protected $primaryKey = 'id';

    protected $fillable = [
        'id', //主键id
        'date', //日期
        'channel_id', //渠道id
        'channel_stage_id', //渠道分期id
        'is_new_user', //是否新用户
        'day_active', //日活
        'recharge_user_num', //充值人数
        'recharge_count', //充值次数
        'recharge_amount', //充值金额
        'lottery_amount', //抽奖金额
        'give_gift_amount', //打赏金额
        'watch_live_duration', //观看直播时长
        'next_day_online_num', //次日留存用户数
        'third_day_online_num', //第三日留存
        'seventh_day_online_num', //第七日
        'fifteenth_day_online_num', //第十五日
        'thirtieth_day_online_num', //第三十日
    ];

    public $timestamps = false;

    public function add($data)
    {
        return $this->insert($data);
    }

    public function edit($where, $data)
    {
        return $this->where($where)->update($data);
    }

    public function getRow($fields, $where)
    {
        return $this->select($fields)->where($where)->first();
    }

    public function formatFieldsWithSum()
    {
        return 'sum(day_active) as day_active,
         sum(recharge_user_num) as recharge_user_num,
          sum(recharge_count) as recharge_count, 
          sum(recharge_amount) as recharge_amount, 
          sum(lottery_amount) as lottery_amount, 
          sum(give_gift_amount) as give_gift_amount, 
          sum(watch_live_duration) as watch_live_duration, 
          sum(next_day_online_num) as next_day_online_num, 
          sum(third_day_online_num) as third_day_online_num,
           sum(seventh_day_online_num) as seventh_day_online_num, 
           sum(fifteenth_day_online_num) as fifteenth_day_online_num, 
           sum(thirtieth_day_online_num) as thirtieth_day_online_num';
    }
}